Conventionally, for example, as disclosed in Japanese Patent Laid-Open Publication No. H10-31553 (hereinafter, referred to as Patent Document 1), there is known an input device that is provided with an acceleration sensor and calculates the direction of gravity of the input device. The input device disclosed in the above Patent Document 1 is provided with an acceleration sensor and calculates the direction of gravity of the input device. Specifically, the input device disclosed in the above Patent Document 1 calculates a combined vector of acceleration indicated by an acceleration signal outputted from the acceleration sensor, and when the magnitude of the combined vector is within a predetermined range with respect to the magnitude of gravitational acceleration, it is determined that the input device is in a static state. Then, the direction of the combined vector that is calculated when it is determined that the input device is in a static state is regarded as the direction of gravity of the input device, and an inclination angle of the input device is calculated.
However, in the input device disclosed in the above Patent Document 1, the direction of gravity becomes difficult to recognize or is falsely recognized depending on the above range for determining that the input device is in a static state. For example, in the above method of calculating the direction of gravity, because the direction of gravity is recognized when the magnitude of the combined vector is within a predetermined range with respect to the magnitude of the gravitational acceleration, the direction of gravity becomes difficult to recognize if the above range is set to a relatively narrow range. On the other hand, if the above range is set to a relatively broad range, a direction that is not the direction of gravity may be recognized as the direction of gravity, resulting in false recognition of the direction of gravity.
Therefore, certain example embodiments provide a storage medium storing an information processing program, and an information processing apparatus, which are capable of accurately calculating the direction of gravity of an input device provided with an acceleration sensor.
Certain example embodiments following features to attain the object mentioned above. It is noted that reference characters and step numbers in parentheses are merely provided to facilitate the understanding of the present invention in relation to later-described embodiments, rather than limiting the scope of the present invention in any way.
A first aspect is a computer-readable storage medium storing an information processing program executed by a computer (10) of an information processing apparatus (5) that executes predetermined processing based on acceleration data (Db, Dm) outputted from an input device (6) including an acceleration sensor (701, 762) for detecting acceleration. The information processing program causes the computer to function as: data obtaining means (CPU 10 executing step 42 and step 102; hereinafter, only step numbers are indicated), change amount calculation means (S51, S121), and gravity direction calculation means (S43, S103, S104). The data obtaining means repeatedly obtains the acceleration data. The change amount calculation means calculates, by using a history of acceleration (a, as) indicated by the acceleration data, a change amount of acceleration generated in the input device. The gravity direction calculation means calculates a direction (g, gs) of gravity of the input device by using the acceleration indicated by the acceleration data, based on the change amount of the acceleration.
According to the above, it is possible to accurately calculate the direction of gravity of the input device including the acceleration sensor, based on the change amount of acceleration generated in the input device (e.g. the difference in acceleration between before and after sampling).
The gravity direction calculation means may calculate a direction of gravity in current processing by correcting a direction of gravity calculated in last processing by using the acceleration indicated by the acceleration data, based on the change amount of the acceleration.
According to the above, it is possible to accurately calculate the direction of gravity of the input device including the acceleration sensor, by correcting the direction of gravity calculated in the last processing by using the acceleration indicated by the acceleration data, based on the change amount of acceleration generated in the input device.
In an example, when the change amount of the acceleration is smaller, the gravity direction calculation means may greatly correct the direction of gravity calculated in the last processing, and may calculate the direction of gravity in the current processing.
According to the above, for example, when the input device is in a static state, the direction of gravity calculated in the last processing is corrected greatly, and hence the direction of gravity can be calculated accurately.
In another example, when the change amount of the acceleration is smaller, the gravity direction calculation means may increase a degree (t, ts) of correcting the direction of gravity calculated in the last processing, and may calculate the direction of gravity in the current processing.
According to the above, the degree of correcting the direction of gravity calculated in the last processing is increased when the change amount of the acceleration generated in the input device is smaller, and the degree at which the previously-set direction of gravity is used for calculation is decreased when the input device is in a static state. Thus, it is possible to accurately calculate the direction of gravity.
In another example, the gravity direction calculation means may execute the correction only when the change amount of the acceleration is equal to or smaller than a predetermined value.
According to the above, when the input device is moved vigorously, acceleration generated by this movement greatly influences the acceleration generated in the input device, and the acceleration generated when the input device is moved vigorously is not used for calculating the direction of gravity, whereby it is possible to accurately calculate the direction of gravity.
The gravity direction calculation means may include temporary credibility calculation means (S51, S121) and credibility setting means (S57, S58, S127, S128). The temporary credibility calculation means calculates, based on the change amount of the acceleration, temporary credibility (d, ds) indicative of a degree at which the acceleration indicated by the acceleration data is credible as gravitational acceleration. The credibility setting means sets, based on the temporary credibility, credibility (t, ts) indicative of a degree of correcting the direction of gravity calculated in the last processing. In this case, the gravity direction calculation means calculates the direction of gravity in the current processing by correcting, in accordance with the credibility set by the credibility setting means, the direction of gravity calculated in the last processing.
According to the above, it is possible to accurately correct the direction of gravity by using the temporary credibility and the credibility.
The temporary credibility calculation means may calculate the temporary credibility so as to be higher when the change amount of the acceleration is smaller. The credibility setting means may set the credibility to be higher when the temporary credibility is higher.
According to the above, when a change of acceleration generated in the input device is small, the temporary credibility and the credibility become high, and thus it is possible to accurately correct the direction of gravity.
The credibility setting means may set credibility in the current processing so as to be difficult to be increased when being higher than credibility set in the last processing, and so as to be easy to be decreased when being lower than the credibility set in the last processing.
According to the above, a substantial increase of the credibility is suppressed when the credibility is higher than that of the last time, and thus a time to wait until the gravitational acceleration generated in the input device is stably detected can be provided. In addition, the credibility is immediately decreased when the credibility is lower than that of the last time, and thus the decrease of the credibility can be immediately reflected in the calculation of the direction of gravity.
The credibility setting means may include high/low determination means (S56). The high/low determination means determines whether or not the temporary credibility calculated by the temporary credibility calculation means is higher than credibility (t0, ts) set in the last processing. In this case, when the high/low determination means determines that the temporary credibility calculated by the temporary credibility calculation means is higher than the credibility set in the last processing, the credibility setting means sets, as credibility in the current processing, a value between the temporary credibility calculated by the temporary credibility calculation means and the credibility set in the last processing.
According to the above, a substantial increase of the credibility is suppressed when the temporary credibility becomes high, and thus a time to wait until the gravitational acceleration generated in the input device is stably detected can be provided.
When the high/low determination means determines that the temporary credibility calculated by the temporary credibility calculation means is equal to or lower than the credibility set in the last processing, the credibility setting means may set, as the credibility in the current processing, a value of the temporary credibility calculated by the temporary credibility calculation means.
According to the above, the credibility is immediately decreased when the temporary credibility becomes low, and thus the decrease of the temporary credibility can be immediately reflected in the calculation of the direction of gravity.
The gravity direction calculation means may calculate the direction of gravity in the current processing by combining, at a rate indicated by the credibility, gravitational acceleration generated in the direction of gravity calculated in the last processing and the acceleration indicated by the acceleration data.
According to the above, the direction of gravity can be corrected naturally.
When the change amount of the acceleration is 0, the gravity direction calculation means may calculate, as a direction of gravity in current processing, the direction of the acceleration indicated by the acceleration data.
According to the above, the acceleration generated in the input device being in a static state is inferred as the gravitational acceleration, and thus it is possible to easily calculate the direction of gravity.
In the first aspect, the information processing program may further cause the computer to function as acceleration vector calculation means (S42). The acceleration vector calculation means calculates an acceleration vector based on the acceleration indicated by the acceleration data obtained by the data obtaining means. In this case, the change amount calculation means calculates a change amount of the magnitude of the acceleration vector by using a history of the acceleration vector. The gravity direction calculation means calculates a gravity direction vector indicative of the direction of gravity of the input device by using the acceleration vector calculated by the acceleration vector calculation means, based on the change amount of the magnitude of the acceleration vector.
The gravity direction calculation means may calculate a gravity direction vector in current processing by combining a gravity direction vector calculated in last processing and the acceleration vector calculated by the acceleration vector calculation means, at a predetermined rate, based on the change amount of the magnitude of the acceleration vector.
According to the above, because the acceleration is handled in the form of vector data, the calculation process is facilitated.
The gravity direction calculation means may decrease the rate of combining the acceleration vector calculated by the acceleration vector calculation means when the change amount of the magnitude of the acceleration vector is greater, and may calculate the gravity direction vector in the current processing.
According to the above, in the case where the input device is not in a static state, the degree of correcting the gravity direction vector calculated in the last processing is decreased when the input device is moved more vigorously, and the degree at which the previously-set gravity direction vector is used for calculation is increased when the input device is moved vigorously. Thus, it is possible to accurately calculate a gravity direction vector.
The gravity direction calculation means may calculate the gravity direction vector in the current processing by combining, at a rate linearly proportional to the change amount of the magnitude of the acceleration vector, the acceleration vector calculated by the acceleration vector calculation means.
According to the above, the current acceleration vector and the gravity direction vector calculated in the last processing can be combined naturally.
In the first aspect, the information processing program may further cause the computer to function as process means (S47). The process means executes a predetermined process by using the acceleration indicated by the acceleration data and with, as a reference, the direction of gravity calculated by the gravity direction calculation means.
According to the above, because the process is executed with, as a reference, the accurately calculated direction of the gravitational force, it is possible to execute a process based on the accurate orientation and motion of the input device.
Further, a second aspect may be implemented in the form of an information processing apparatus including the above means.
According to certain example embodiments, it is possible to calculate the direction of gravity of the input device including the acceleration sensor, based on the change amount of the acceleration generated in the input device (e.g. the difference in acceleration between before and after sampling).
These and other objects, features, aspects and advantages of certain example embodiments will become more apparent from the following description when taken in conjunction with the accompanying drawings.